import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
import statsmodels.api as sm
from sklearn.linear_model import LinearRegression

# 准备数据
boston = datasets.load_boston()
# print(boston.feature_names)
x = boston.data
y = boston.target
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=100)
lr = LinearRegression()
lr.fit(x_train, y_train)
# print(f'截距：{lr.intercept_}')
# print(f'系数：{lr.coef_}')
# print(f'准确率：{lr.score(x_test, y_test)}')

x_b = sm.add_constant(x)  #增加常数列
linear_model = sm.OLS(y, x_b)
results = linear_model.fit()
# print(results.summary())

print(np.var(2))


